#include "stdafx.h"
#include "SamplerState.h"

namespace Reign
{namespace Video
{namespace D3D10
{
	#pragma region Constructor
	SamplerState::SamplerState(DisposableI^ parent, SamplerStateDescI^ desc)
	: Disposable(parent)
	{
		null();
		try
		{
			video = parent->FindParentOrSelfWithException<Video^>();

			ID3D10SamplerState* samplerStateTEMP;
			SamplerStateDesc^ descTEMP = (SamplerStateDesc^)desc;
			if (FAILED(video->Device->CreateSamplerState(descTEMP->Desc, &samplerStateTEMP)))
			{
				Debug::ThrowError(L"SamplerState", L"Failed to create SampleState");
			}
			samplerState = samplerStateTEMP;
		}
		catch (Exception^ ex)
		{
			delete this;
			throw ex;
		}
	}

	SamplerState::~SamplerState()
	{
		disposeChilderen();
		if (samplerState) samplerState->Release();
		null();
	}

	void SamplerState::null()
	{
		samplerState = 0;
	}
	#pragma endregion
	
	#pragma region Methods
	void SamplerState::Enable(int index)
	{
		ID3D10SamplerState* samplerStateTEMP = samplerState;
		video->Device->PSSetSamplers(index, 1, &samplerStateTEMP);
	}
	#pragma endregion
}
}
}